using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace CommandPatternApp
{
    public class CmdMenuItem : MenuItem
    {
        private BaseCmd _command;

        public CmdMenuItem()
            : base()
        {
            this.Click += new EventHandler(MenuItemClick);
            _command = null;
        }

        public BaseCmd Command
        {
            get { return _command; }
            set { _command = value; }
        }

        private void MenuItemClick(object sender, EventArgs args)
        {
            if (_command != null) _command.Execute();
        }
    }
}
/*
internal class SampleEditor
{
    private SampleFactory m_Factory;
    private readonly Stack<SampleCommand> m_Stack = new Stack<SampleCommand>();

    public SampleFactory Factory
    {
        get
        {
            if (m_Factory == null)
                m_Factory = new SampleFactory();
            return m_Factory;
        }
    }

    internal void Push(SampleCommand command) { m_Stack.Push(command); }

    public void Undo() 
    { 
        SampleCommand command = m_Stack.Pop(); 
        command.UnDo(); 
    }
}

internal class SampleFactory
{
    private SampleEditor m_Editor;
    internal SampleFactory(SampleEditor editor) { m_Editor = editor; }

    // Parameterless methods could be "get" properties....
    public SampleCommand Cut() { return new CutCommand(m_Editor); }
    public SampleCommand Copy() { return new CopyCommand(m_Editor); }
    public SampleCommand Paste() { return new PasteCommand(m_Editor); }
    public SampleCommand Insert(string text) { return new InsertCommand(m_Editor, text); }
}

class SampleCommand
{
    private SampleEditor m_Editor;
    public SampleCommand(SampleEditor editor) { m_Editor = editor; }
    public void Execute() { }
    public void UnDo() { }
}
*/

